
function MainController($http, $scope, $timeout, ngDialog) {
  'ngInject';

  let _this = this;

  this.queryData = {};

  // 获取红黑榜6条
  this.paginationData = {
    pageNum: 1,
    pageSize: 6,
    total: '',
  }
  
  this.getCheckStatus = (status) => {
    switch(status) {
      case 0:
        return '待整改';
        break;
      case 1:
        return '待审核';
        break;
      case 2:
        return '已完成';
        break;
      case 3:
        return '符合要求';
        break;
    }
  }

  // 红黑榜数据
  this.topList = {
    redList: [],
    blackList:[]
  };

  // 轮播图
  this.slides = [
    {
      id:'01',
      image:'../assets/images/img1.png',
    },
    {
      id:'02',
      image:'../assets/images/img2.png',
    },
    {
      id:'03',
      image:'../assets/images/img3.png',
    },
  ]

  // 项目公告
  this.projectNoticeList = {};

  // 问题追踪
  this.problemTrackingList = {};

  // 单位概况
  this.unitList = [];

  // 获取项目公告
  this.getProjectNotice = () => {
    $http.post(`${SERVER_CONTEXT}/api/user/app/notice/queryNoticeList`,{pageNum: 0, pageSize: 6, total: ''})
      .then((resp) => {
        this.projectNoticeList = resp.data.data;
    });
  }

  var now = new Date;

  // 获取问题追踪
  this.getInspectContent = () => {
    $http.post(`${SERVER_CONTEXT}/api/checkRecord/app/queryCheckProblemListByCondition`,{pageNum: 0, pageSize: 5, total: ''})
      .then((resp) => {
        this.problemTrackingList = resp.data.data;
        this.problemTrackingList.forEach((item) => {
          var d = new Date(item.problemDeadline1);
          if (now > d) {
            item.active = true;
          }  
        })
    });
  }

  // 获取单位概况
  this.unitOverview = () => {
    $http.get(`${SERVER_CONTEXT}/api/homePage/app/queryAllUnitDetails`)
      .then((resp) => {
        this.unitList = resp.data;
    });
  }

  //获取红榜
  let reqData = {
    rbType:1
  }
  this.getHongBang = () => {
    $http.post(`${SERVER_CONTEXT}/api/redBlack/redBlackList/selectRedBlackList`,
      angular.extend(reqData,this.paginationData)
        )
        .then((resp) => {
          this.topList.redList = resp.data.data;
        })
  }

  // 获取黑榜
  let resHeiData = {
    rbType:0
  }
  this.getHeiBang = () => {
    $http.post(`${SERVER_CONTEXT}/api/redBlack/redBlackList/selectRedBlackList`,
      angular.extend(resHeiData,this.paginationData)
        )
        .then((resp) => {
          this.topList.blackList = resp.data.data;
        });
  }


  this.initPage = () => {

    // 获取项目公告
    this.getProjectNotice();

    // 获取问题追踪
    this.getInspectContent();

    // 获取单位概况
    this.unitOverview();

    // 获取红榜
    this.getHongBang();

    // 获取黑榜
    this.getHeiBang();
  }

  // 初始化页面
  this.initPage();
}

export default MainController;
